<!--
 * @Description: 
 * @Author: zzj
 * @Date: 2021-10-11 11:50:50
 * @LastEditors: zzj
 * @LastEditTime: 2021-10-11 17:17:11
-->
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>组件</title>
	<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.js"></script>
</head>

<body>
	<div id="app">
		<briup-info @close="close" msg="hello"></briup-info>
		<briup-info @close="close" msg="你好"></briup-info>
	</div>

	<script>
		//1.定义组件
		let briupInfo = {
			template: `
				<div ref="info" :style="{
					padding:'1em',
					backgroundColor:'plum',
					borderRadius:'5px',
					marginBottom:'1em'
				}">
					{{msg}}

					<button @click="closeHandler(msg)">关闭</button>
				</div>
			`,
			props: ["msg"],
			methods:{
				closeHandler(msg){
					this.$refs.info.style.display = "none";
					//通知、发射事件
					this.$emit("close",msg)
				},
			}
		}

		//2.注册组件   全局注册   一定在初始化之前进行注册
		Vue.component("briup-info", briupInfo)
		//3.使用组件


		new Vue({
			el: "#app",
			methods:{
				close(msg){
					alert("关闭了一个消息框" + msg)
				}
			}
		})
	</script>
</body>

</html>